package com.ruoyi.web.controller.feign;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.feign.RemoteMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Feign远程调用测试
 */
@Anonymous
@RestController
@RequestMapping("/feign/test")
public class FeignTestController extends BaseController {

    @Autowired
    private RemoteMessageService remoteMessageService;

    /**
     * 测试远程调用
     */
    @GetMapping("/remote/{name}")
    public AjaxResult remoteCall(@PathVariable("name") String name) {
        try {
            String result = remoteMessageService.getMessage(name);
            return AjaxResult.success("远程调用成功", result);
        } catch (Exception e) {
            return AjaxResult.error("远程调用失败: " + e.getMessage());
        }
    }
}
